/*
 *  Copyright 2012 Iurii Dunko, Iana Potochniak.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.yyminijava.execution;

import java.io.IOException;
import org.opu.yyminijava.util.ArgsParserr;

/**
 *
 * @author Iurii Dunko
 * @author Iana Potochniak
 */
public class Main {

    public static void main(String[] args) throws IOException {
        ArgsParserr ap = new ArgsParserr(args);
        String fname = ap.getArg(0);
        if (fname == null || ap.contains('h') ){
            helpAndExit();
        }

        execute(fname, ap.contains('d'));
    }

    public static void execute(String fname, boolean debug) throws IOException {
        Interpreter interpreter = new TJInterpreter(fname, debug);
        interpreter.startExecution();
    }

    private static void helpAndExit() {
		System.out.println("Use: java -jar <application> [arguments] <grammar file> [arguments]");
		System.out.println("  <application>  - execution-0.0.1-jar-with-dependencies.jar");
		System.out.println("  <grammar file> - input file");
		System.out.println("  arguments (unix like - '-hd' = '-h -d'):");
		System.out.println("    -h  print this help and exit");
		System.out.println("    -d  print execution stack");
		System.out.println();
		System.out.println("Example of execution may be: ");
		System.out.println("  java -jar execution-0.0.1-jar-with-dependencies.jar MyApp.tjc");
		System.out.println();
		System.exit(1);
    }
}
